package com.alumni_circle.core.mapper.rbac;

import com.alumni_circle.core.entity.rbac.UserRole;
import com.alumni_circle.core.entity.rbac.VO.UserRoleViewVO;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @author 龙小虬
 * @since 2020-08-02 20:25
 */
public interface UserRoleMapper extends BaseMapper<UserRole> {

    @Select(" select user.username,role.role_name,user_role.id,user_role.update_name,user_role.update_time,user_role.state " +
            "from user_role,user,role " +
            "where user_role.user_id = user.id and user_role.role_id = role.id")
    List<UserRoleViewVO> getAllUserRole();

    @Select(" select user.username,role.role_name,user_role.id,user_role.update_name,user_role.update_time,user_role.state " +
            "from user_role,user,role " +
            "where user_role.user_id = user.id and user_role.role_id = role.id " +
            "and (user.username LIKE concat('%',#{username},'%') " +
            "and user_role.update_name LIKE concat('%',#{updateName},'%') " +
            "and user_role.state LIKE concat('%',#{state},'%') " +
            "and role.role_name LIKE concat('%',#{roleName},'%') " +
            "and user_role.update_time LIKE concat('%',#{updateTime},'%') " +
            "and user_role.id LIKE concat('%',#{id},'%'))")
    List<UserRoleViewVO> searchUserRole(@Param("id")String id,@Param("username")String username,@Param("updateName")String updateName,@Param("state")String state,@Param("roleName")String roleName,@Param("updateTime")String updateTime);
}
